from reward_component import RewardComponent

class CostReductionComponent(RewardComponent):
    """成本节约奖励组件"""
    def __init__(self, weight=1.0, cost_data=None):
        super().__init__(weight)
        self.cost_data = cost_data or {}
        
    def calculate(self, current_activity, next_activity, case_events, context=None):
        # 获取活动成本数据
        cost = self.cost_data.get(next_activity, 0)
        avg_cost = sum(self.cost_data.values()) / len(self.cost_data) if self.cost_data else 1
        
        # 计算成本节约率 (负值表示成本高于平均)
        normalized_cost = -1 * (cost / avg_cost - 1)
        return normalized_cost
        
    def get_description(self):
        return "基于活动成本节约的奖励"